﻿using System;
using System.Collections.Generic;
using VkApiVer2.api.Enums;
using VkApiVer2.extensions;

namespace VkApiVer2.api.Utils
{

    public static class FieldsUtils
    {

        public static String ConvertFieldsToString(Field field)
        {
            return string.Join(",", GetCheckedFieldsString(field));
        }

        public static Field GetAllFields()
        {
            Field allFields = 0;
            foreach(var value in Enum.GetValues(typeof(Field)))
            {
                allFields |= (Field)value;
            }
            return allFields;
        }

        private static IEnumerable<string> GetAllFieldsString()
        {
            foreach(string field in Enum.GetNames(typeof(Field)))
                yield return field.ToLower();
        }

        private static IEnumerable<string> GetCheckedFieldsString(Field field)
        {
            foreach(Field value in Enum.GetValues(typeof(Field)))
            {
                if(!field.IsSet(value)) continue;
                yield return Enum.GetName(typeof(Field), value).ToLower();
            }
        }
    }
}
